package com.taotao.service.impl;

import com.taotao.mapper.TbItemCatMapper;
import com.taotao.pojo.EasyUITreeNode;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by new on 2018/6/3.
 */
@Service
public class ItemCatServiceImpl implements ItemCatService{

    @Autowired
    private TbItemCatMapper itemCatMapper;

    @Override
    public List<EasyUITreeNode> getItemCatList(Long parentId) {

        TbItemCatExample tbItemExample = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = tbItemExample.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        List<TbItemCat> tbItemCats = itemCatMapper.selectByExample(tbItemExample);
        List<EasyUITreeNode> nodeList = new ArrayList<>();
        for(TbItemCat cat: tbItemCats){
            EasyUITreeNode node = new EasyUITreeNode();
            node.setId(cat.getId());
            node.setState(cat.getIsParent()?"closed":"open");
            node.setText(cat.getName());
            nodeList.add(node);
        }

        return nodeList;
    }
}
